//
//  WBPresentationController.swift
//  sxwb
//
//  Created by TianDu on 2016/11/14.
//  Copyright © 2016年 TianDu. All rights reserved.
//

import UIKit

class WBPresentationController: UIPresentationController {

    lazy var coverView = UIView()
    
    var presentFrame = CGRect.zero
    
    
    /// 重写containerViewWillLayoutSubviews来改变弹出的控制器的大小
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        ///设置弹出的view的frame
        presentedView?.frame = presentFrame
        
        ///设置蒙层
        containerView?.insertSubview(coverView, belowSubview: presentedView!)
        coverView.backgroundColor = UIColor(white: 0.8, alpha: 0.2)
        coverView.frame = containerView!.bounds
        
        ///给蒙层添加手势
        let tap = UITapGestureRecognizer(target: self, action: #selector(coverTap))
        coverView.addGestureRecognizer(tap)
    }
    
    func coverTap() {
        
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}
